import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

class Solution1027 {
    public static void main(String[] args) {
        int[] arr = {83,20,17,43,52,78,68,45};
        System.out.println(longestArithSeqLength(arr));
    }
    public static int longestArithSeqLength(int[] nums) {
        int n = nums.length ;
        Map<Integer , Integer> hash = new HashMap<>() ;
        int[][] dp = new int[n][n] ;
        int max = 2  ;
        for(int i=0 ; i < n ; i ++){
            for(int j=i+1 ; j < n ; j++){
                dp[i][j] = 2 ;
                int d = nums[j] - nums[i] ;
                int k = nums[i] - d ;
                if(hash.containsKey(k)){
                    dp[i][j] = dp[hash.get(k)][i] + 1 ;
                    max = Math.max(max , dp[i][j]) ;
                }
            }

            hash.put(nums[i] , i) ;
        }


        return max ;
    }
}